#include <iostream>
#include <opencv4/opencv2/core/core.hpp>
#include <opencv4/opencv2/highgui/highgui.hpp>
#include <chrono>

using namespace std;
using namespace cv;

int main(int argc, char **argv) 
{
    cv::Mat image;
    image=cv::imread(argv[1]);
    
    if(!image.data)
    {
        cout<<"can't read the image"<<endl;
        return 0;
    }
    
    cout<<"the hight of the image is "<<image.rows<<" the width of the image is "<<image.cols
    <<" the channels of the image is "<<image.channels()<<endl;
    
    imshow("image",image);
    waitKey(0);
    
    if(image.type()!=CV_8UC1&&imag.type()!=CV_8UC3)
    {
        cout<<"input an color or gray image"<<endl;
        return 0;
    }
    
    chrono::steady_clock::time_point t1=chrono::steady_clock::now();
    for(size_t y=0;y<image.rows;y++)
    {
        unsigned char* row_prt=image.prt<unsigned char>(y); //第y行的头指针；
        
        for(size_t x=0;x<image.clos;x++)
        {
            unsigned char* data_prt=&row_prt[x*image.channels()];
            
            for(int c=0;c!=image.channels();c++)
            {
                unsigned char data=data_prt[c];
            }
        }
    }
    chrono::steady_clock::time_point t2=chrono::steady_clock::now();
    chrono::duration<double> time_used=chrono::duration_cast <chrono::duration<double>>(t2-t1);
    
    cout<<"便利图像的每一个像素"<<endl;
    
    cv::Mat image_clone=image.clone();
    image_clone(cv::Rect(0,0,100,100)).setTo(255);
    cv::imshow("image", image);
    cv::imshow("image_clone",image_clone);
    cv:: waitKey(0);
    cv::destroyAllWindows();
    return 0;
}
